<template>
    <el-card>
        <el-form :model="queryParams" ref="queryParams" :inline="true" label-width="120px">
            <!-- <el-form-item label="申请时间：" prop="service">
                 <el-select v-model="queryParams.service" placeholder="请选择" size="small">
                    <el-option v-for="item in FrontendList" :label="item" :key="item" :value="item"></el-option>
                  </el-select>
            </el-form-item> -->
            <el-form-item label="标题" prop="title">
                <el-input v-model="queryParams.title" placeholder="接口名" size="small"></el-input>
            </el-form-item>
             <el-form-item label="审核结果" prop="approvalResult">
                 <el-select v-model="queryParams.approvalResult" placeholder="请选择" size="small">
                    <el-option v-for="item in approvalArr" :label="item.label" :key="item.value" :value="item.value"></el-option>
                  </el-select>
            </el-form-item>
            <el-form-item >
                <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-delete" size="small" @click="resetQuery('queryParams')">清空</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" size="small">
            <el-table-column type="index" label="#" width="50"></el-table-column>
            <el-table-column label="申请时间" prop="applyTime"></el-table-column>
            <el-table-column label="标题" prop="title"></el-table-column>
            <el-table-column label="申请人" prop="approvalBy"></el-table-column>
            <el-table-column label="申请类型" prop="type"></el-table-column>
            <el-table-column label="审核人" prop="applyBy"></el-table-column>
            <el-table-column label="审核结果" prop="approvalResult">
                <template slot-scope="{row}">
                    <el-tag type="primary">{{approvalArr.find(item=>item.value===row.approvalResult).label}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="审核时间" prop="approvalTime"></el-table-column>
            <el-table-column label="操作" width="100" align="center">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row.id)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
         <el-pagination
                v-show="total>0"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                background
                :current-page="1"
                :page-sizes="[10, 20, 30, 40,50,100]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                class="pagination-container"
                :total="total">
        </el-pagination>
        <el-dialog title="发布|下线审核日志" width="40%" :visible.sync="dialogVisible">
            <el-row>
              <el-col :span="4">
                  <h4>操作以下接口：</h4>
              </el-col>
            </el-row>
            <el-table :data="apiTableData" border size="small" style="margin: 10px">
                <el-table-column label="所属服务" prop="serviceName"></el-table-column>
                <el-table-column label="接口名" prop="configName"></el-table-column>
            </el-table>
             <el-form :model="form" label-width="100px" disabled>
               <el-form-item label="标题" prop="title">
                   <el-input v-model="form.title" size="small"></el-input>
               </el-form-item>
               <el-form-item label="申请类型" prop="type">
                   <el-input v-model="form.type" size="small">
                       <template slot-scope="{row}">
                           <span v-if="row.type===0">发布</span>
                           <span v-if="row.type===1">下线</span>
                       </template>
                   </el-input>
               </el-form-item>
               <el-form-item label="申请原因" prop="reason">
                   <el-input v-model="form.reason" size="small"></el-input>
               </el-form-item>
               <el-form-item label="申请人" prop="approvalBy">
                   <el-input v-model="form.approvalBy" size="small"></el-input>
               </el-form-item>
               <el-form-item label="申请时间" prop="applyTime">
                   <el-input v-model="form.applyTime" size="small"></el-input>
               </el-form-item>
               <el-form-item label="审核人" prop="approvalBy">
                   <el-input v-model="form.approvalBy" size="small"></el-input>
               </el-form-item>
               <el-form-item label="审核备注" prop="approvalRemark">
                   <el-input v-model="form.approvalRemark" size="small"></el-input>
               </el-form-item>
               <el-form-item label="审核时间" prop="applyTime">
                   <el-input v-model="form.applyTime" size="small"></el-input>
               </el-form-item>
             </el-form>
           
        </el-dialog>
   </el-card>
</template>

<script>
import { getAuditLogList,getAuditLogDetail } from '@/api/aggregate/auditLog.api.js'
    export default {
        data() {
          return {
            queryParams: {
                current: 1,
                size: 10,
                title: undefined,
                approvalResult: undefined,
            },
            tableData: [],
            approvalArr: [
                {label: '不通过',value: 1},
                {label: '通过',value: 2},
            ],
            total: 0,
            FrontendList: [],
            apiTableData: [],
            dialogVisible: false,
            form: {
                title: undefined,
            }
          }
        },
        mounted() {
            this.getList();
        },
        filters: {
            statusFilter(value) {
                if(value===1) {
                    return '未发布';
                }
            }
        },
        methods: {
            async handleView(id) {
                const result = await getAuditLogDetail(id);
                if(result.code === 200) {
                    this.apiTableData = result.data.configs;
                    this.form = result.data;
                    this.dialogVisible = true;
                }
            },
            async getList() {
                const result = await getAuditLogList(this.queryParams);
                if(result.code === 200) {
                    this.tableData = result.data.records;
                    this.total = result.data.total
                }
            },
              // 搜索
            handleQuery() {
                this.queryParams.current = 1;
                this.getList();
            },
            // 清空
            resetQuery(formName) {
                this.$refs[formName].resetFields();
                this.getList();
            },
            handleSizeChange(val) {
                this.queryParams.size = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.queryParams.current = val;
                this.getList();
            },
        }
    }
</script>
<style lang="scss" scoped>
.pagination-container {
    padding: 10px;
    text-align: right;
}
</style>